var web = document.querySelector(".web");
var web1 = document.querySelector(".web1");
var light = document.querySelector(".light");
var lightImg = light.querySelector("img");
var count = 1;
var lightOne = "light.png";
var lightTwo = "light2.png";
var span = document.querySelector("span");
var audio = document.querySelector("audio");
//灯光切换
setInterval(function time(){
	if(count == 1){
		lightImg.src = "img/"+lightTwo;
		count = 0;
	}else{
		lightImg.src = "img/"+lightOne;
		count = 1;
	}
},500)
//倒计时
var arr = [];
for(let i=60;i>=0;i--){
	arr.push(i);
}
var j = 0;
setInterval(function timer(){
	if(j==arr.length){
		setTimeout(timer);
	}else{
		span.innerText = arr[j];
		j++;
	}
	
},1000)
//获取缓存的歌曲信息和答案选择
var music = sessionStorage.getItem("Arr");
console.log(JSON.parse(music));
music = JSON.parse(music);
var s = 0; 
function song(s){
	var _audio = music[s].audio;
	audio.src = _audio;//歌曲路径
}
song(s);
//获取p标签
var allP = document.querySelectorAll("p"); 
var a = document.querySelector(".a");
var b = document.querySelector(".b");
var c = document.querySelector(".c");
var chick = [];
chick.push(a,b,c);
//叉叉和勾勾
for(let k=0;k<music[s].item.length;k++){
	allP[k].innerText = music[s].item[k];
	//点击事件
	chick[k].addEventListener("touchend",function(e){
		if(k==music[s].answer){
			var yes = this.querySelector(".yes");
			yes.style.display = "inline-block";
			s++;
			j = 0;
			setTimeout(function(){
				for(let m = 0;m<music[s].item.length;m++){
				allP[m].innerText = music[s].item[m];
				}
				yes.style.display = "none";
				song(s);
				web.style.display = "none";	
				web1.style.display = "block";
			},1000)
		}else{
			var wrong = this.querySelector(".wrong");
			wrong.style.display = "inline-block";
			var yes = chick[music[s].answer].querySelector(".yes");
			yes.style.display = "inline-block";
			s++;
			j = 0;
			setTimeout(function(){
				for(let m = 0;m<music[s].item.length;m++){
				allP[m].innerText = music[s].item[m];
				}
				wrong.style.display = "none";
				yes.style.display = "none";
				song(s);
				web.style.display = "none";
				web1.style.display = "block";
			},1000)
		}
	})
}

